package com.sacc.controller;

import com.google.gson.Gson;
import com.power.common.model.CommonResult;
import com.sacc.pojo.ProductInfoAll;
import com.sacc.pojo.ProductList;
import com.sacc.service.ProductInfoAllService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author 滚~韬
 * @date 2022/4/8 15:12
 */
@RestController
@RequestMapping("/product/product")
public class ProductInfoAllController {

    @Autowired
    private ProductInfoAllService productInfoAllService;
    //根据产品id去获取一个产品信息
    @GetMapping("/getoneinfo")
    ProductInfoAll GetOneInfo(@RequestParam Integer productId){
        return productInfoAllService.GetOneInfo(productId);
    }

    //根据产品id去获取一个产品列表
    @GetMapping("/getonelist")
    ProductInfoAll GetOneList(@RequestParam Integer productId){
        return productInfoAllService.GetOneList(productId);
    }

    //获取产品列表
    @GetMapping("/getall")
    List<ProductInfoAll> GetAll(){
        return  productInfoAllService.GetAll();
    }
    //添加一个产品信息
    @PostMapping("/addone")
    CommonResult AddOne(String productInfoAll, MultipartFile[] files){
        Gson gson = new Gson();
        ProductInfoAll productInfoAllObject = gson.fromJson(productInfoAll, ProductInfoAll.class);
        return productInfoAllService.AddOne(productInfoAllObject,files);
    }
    @PostMapping("/updateone")
    CommonResult UpdateOne(Integer productId, MultipartFile[] files){
        return productInfoAllService.UpdateOne(productId,files);
    }
}
